package com.example.admin;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Description: SpringBootAdmin服务监控
 * @Author kaka
 * @Date 2022/12/27 10:18
 */
@Slf4j
@EnableAdminServer
@SpringBootApplication
public class SpringBootAdminApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SpringBootAdminApplication.class, args);

        Environment environment = context.getBean(Environment.class);
        String applicationName = environment.getProperty("spring.application.name");
        log.info("{}启动成功", applicationName);
        String localUrl = "http://localhost:" + environment.getProperty("server.port");
        String contextPath = environment.getProperty("server.servlet.context-path");
        if (contextPath != null && !contextPath.isEmpty()) {
            localUrl += contextPath;
        }
        log.info("\n ============> 本地spring-boot-admin访问地址：{}", localUrl);
        try {
            log.info("\n ============> 本地本机ip：\u001B[34m{}\u001B[0m", InetAddress.getLocalHost().getHostAddress());
        } catch (UnknownHostException e) {
            log.error("获取本地本机ip异常", e);
        }
    }


}
